From 67ce109d119f01907ed90dba43d231a63cca8520 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Thu, 15 Dec 2016 02:08:46 +0100 Subject: [PATCH] extensions/cairo: regain some lost speed for 32bit linear float display --- extensions/cairo.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/extensions/cairo.c b/extensions/cairo.c index 6bfc574..cda5eaa 100644 --- a/extensions/cairo.c +++ b/extensions/cairo.c @@ -137,6 +137,30 @@ conv_yA16_cairo32_le (unsigned char *src, unsigned char *dst, long samples) return samples; } +static long +conv_rgbA_gamma_float_cairo32_le (unsigned char *src, + unsigned char *dst, + long samples) +{ + float *fsrc = (float *) src; + unsigned char *cdst = (unsigned char *) dst; + int n = samples; + + while (n--) + { + int val = fsrc[2] * 255.0f + 0.5f; + *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = fsrc[1] * 255.0f + 0.5f; + *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = fsrc[0] * 255.0f + 0.5f; + *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + val = fsrc[3] * 255.0f + 0.5f; + *cdst++ = val >= 0xff ? 0xff : val <= 0 ? 0 : val; + fsrc+=4; + } + return samples; +} + static long conv_rgbafloat_cairo32_le (unsigned char *src, unsigned char *dst, @@ -226,6 +250,9 @@ init (void) babl_conversion_new (babl_format ("RGBA float"), f32, "linear", conv_rgbafloat_cairo32_le, NULL); + babl_conversion_new (babl_format ("R'aG'aB'aA float"), f32, "linear", + conv_rgbA_gamma_float_cairo32_le, NULL); + babl_conversion_new (babl_format ("R'G'B'A u8"), f24, "linear", conv_rgba8_cairo24_le, NULL); babl_conversion_new (babl_format ("R'G'B' u8"), f24, "linear", -- 2.30.2